#include "Acombine.h"
bool GetCombine(CDraw &para,MyPlots* plots,AObject &object, AnalyseClass &analyse){
	para.status.Set_Current_Position("begin combine");


	bool Jcomb        = false;
	bool Jrecoil      = false;
	bool Jcomb_recoil = false;
	bool Jcombine     = false;

	if(para.comb.SWITCH){
		para.debug.Message(4,2,"begin combine");
		Jcomb=Analysis_Combine(para,plots,object, analyse);
		para.debug.Message(4,2,"end combine detail");
	}
	else{Jcomb=true;}

	if(para.recoil.SWITCH){
		para.debug.Message(4,2,"begin recoil");
		Jrecoil=Analysis_Recoil(para,plots,object);
		if(Jrecoil){analyse.counter.getCounter("operation_recoil");}
	}
	else{Jrecoil=true;}


	if(para.recoil.comb_SWITCH){
		para.debug.Message(4,2,"begin combine and recoil");
		Jcomb_recoil=Analysis_Combine_Recoil(para,plots,object.Vjet,object.Vbjet,object.Vcjet,object.Vqjet, object.Velec,object.Vmuon,object.Vcombine_jet1,object.Vcombine_jet2, object.Vcombine_elec1, object.Vcombine_elec2, object.Vcombine_muon1, object.Vcombine_muon2);
		if(Jcomb_recoil){analyse.counter.getCounter("operation_recoil_comb");}
	}
	else{Jcomb_recoil=true;}

	if(para.flow.record_event){
//		object.Fill_Combine(para,analyse,Jcomb);
	}
	if(Jcomb&&Jrecoil&&Jcomb_recoil){
		Jcombine=true;
		analyse.counter.getCounter("operation");
		para.debug.Message(4,2,"end combine");
		return(true);
	}
	else{
		return(false);
	}
}

bool Analysis_Combine(CDraw &para, MyPlots *plots, AObject& object, AnalyseClass &analyse){
	para.status.Set_Current_Position("begin combine 2");

	//ShowMessage(2,"one event begin");
	ACuts_Vector cuts=para.comb.comb_cuts;
	//cuts_vector.Print();
	AComb_LTV signal_ss_lep(object.Lsignal_lep_p, object.Lsignal_lep_m, cuts.cut_vector[0], "SS_lep");
	bool JSSLepton=Combine_Get_SameSignLepton(signal_ss_lep);
	if(!JSSLepton){return(false);}
	signal_ss_lep.Set_Distance();
	//signal_ss_lep.Print();

	AComb_LTV signal_light_higgs(object.Lsignal_tagjet, cuts.cut_vector[1], 1, "light_higgs");
	bool JMbb=signal_light_higgs.Combine_SameFS();
	if(!JMbb){return(false);}
	signal_light_higgs.Set_Distance();
	//signal_light_higgs.Print();

	
	AComb_LTV signal_met(object.Lmet, 1, "MET");
	AComb_LTV signal_CH(cuts.cut_vector[2],"Charged");
	Find_CH_Combination(para, signal_ss_lep, signal_light_higgs, signal_met, cuts.cut_vector[2], signal_CH);
	signal_CH.Set_Distance();
	//signal_met.Print();
	//signal_CH.Print();


	AComb_Vector comb_vector;
	comb_vector.Add_LTV(signal_ss_lep);
	comb_vector.Add_LTV(signal_light_higgs);
	comb_vector.Add_LTV(signal_CH);
	//comb_vector.Set_Distance_Self();
	//comb_vector.Set_Distance_Inter();
	comb_vector.Set_Distance();
	comb_vector.Print();
	comb_vector.Assign_Variables(para, analyse.var);
	exit(0);
	//ShowMessage(2,"var size final",analyse.var.var.size());
//	comb_vector.Print();
//	analyse.var.Print("var");
	//
	//AComb_Inter inter_lep_lh;
	//inter_lep.Set_Variables(signal_ss_lep.out, signal_light_higgs.out);
	//inter.Set_Distance();
	//inter.Print();

	//AComb_Inter inter;
	//inter.Set_Variables(signal_ss_lep.out, signal_light_higgs.out);
	//inter.Set_Distance();
	//inter.Print();
	//signal_CH.Print("signal_CH");
	//signal_met_in_CH.Print("signal_met_in_CH");
	//ShowMessage(2,"one event finished");



	//if(num_lep<para.signal.NUM_lep || num_jet<para.signal.NUM_jets){
	//	return(false);
	//}
//object.Vcombine1.resize(1);
//object.Vcombine2.resize(1);
//object.Vcombine3.resize(2);
//object.Vcombine4.resize(1);
//object.Vcombine5.resize(1);
//object.Vcombine6.resize(1);
//object.Vcombine7.resize(1);
//object.Vcombine8.resize(1);
	/*
		if(Jcomb1){analyse.counter.getCounter("operation_combine1");}
		if(Jcomb2){analyse.counter.getCounter("operation_combine2");}
		if(Jcomb3){analyse.counter.getCounter("operation_combine3");}
		if(Jcomb4){analyse.counter.getCounter("operation_combine4");}
		if(Jcomb5){analyse.counter.getCounter("operation_combine5");}
		if(Jcomb6){analyse.counter.getCounter("operation_combine6");}
		if(Jcomb7){analyse.counter.getCounter("operation_combine7");}
		if(Jcomb8){analyse.counter.getCounter("operation_combine8");}
		*/
//	object.Vvalue.resize(2);

//	object.Vvalue[1]=1.0;
//	ShowMessage(2,"same sign lepton num", para.Event(), object.Vvalue[1]);
	//two light higgs
//	ShowMessage(4,"begin combine resonance");
//	ShowMessage(4,"jet momentum ",object.Lsignal_tagjet);
	//*Jcomb1=Combine2SameFS_TLorentzvector(para,plots->fcomb2M,object.Lsignal_tagjet,Icomb1_m,cut_mlow2, cut_mup2, cut_ptlow2, cut_ptup2, object.Vcombine2[0]);
//	ShowMessage(4,"end combine jet",object.Vcombine2);
//	ShowMessage(4,"lepton momentum ",object.Lsignal_lep);
	//*Jcomb2=Combine2SameFS_TLorentzvector(para,plots->fcomb1M,object.Lsignal_lep,Icomb1_m,cut_mlow1, cut_mup1, cut_ptlow1, cut_ptup1, object.Vcombine1[0]);
//	ShowMessage(4,"end combine lepton",object.Vcombine1);
	//*Jcomb3=CombineMoreWith2DifferentFS_TLorentzvector(para, plots->fcomb3M, object.Lsignal_lep, object.Lsignal_tagjet, Icomb3_m, object.Vcombine3);
//	ShowMessage(4,"cut1",Icomb3_m, object.Vcombine3[0].M(), object.Vcombine3[1].M());
//	ShowMessage(4,"end combine lep-jet ",object.Vcombine3);

//	ShowMessage(4,"begin combine vis=2lep-2jet ", object.Lvis);
//	ShowMessage(4,"begin combine cut 4 ", cut_mlow4, cut_mup4);
	//*Jcomb4=reconstruct_visible(para,plots->fcomb4M,object.Lvis,cut_mlow4, cut_mup4, object.Vcombine4[0], object.Vvalue[0]);
//	ShowMessage(4,"end combine vis=2lep-2jet ", object.Vcombine4);
//	ShowMessage(4,"end combine HT", object.Vvalue[0]);
//	ShowMessage(4,"begin combine lep_lep", object.Vangle_lep.size());
	//*Jcomb5=CombineSameAngles_TLorentzvector(para,plots->fcomb5M,object.Lsignal_lep,object.Vangle_lep);
//	ShowMessage(4,"end combine lep_lep angles",object.Vangle_lep[0]);
	//*Jcomb6=CombineSameAngles_TLorentzvector(para,plots->fcomb6M,object.Lsignal_lep,object.Vangle_jet);
//	ShowMessage(4,"end combine jet_jet angles",object.Vangle_jet[0]);
	//*Jcomb7=Combine2DifferentAngles_TLorentzvector(para,plots->fcomb7M,object.Lsignal_lep,object.Lsignal_tagjet,object.Vangle_lep_jet);
//	ShowMessage(4,"end combine lep_jet angles",object.Vangle_lep_jet[0],object.Vangle_lep_jet[1],object.Vangle_lep_jet[2],object.Vangle_lep_jet[3]);
	//*Jcomb8=CombineSameAngles_TLorentzvector(para,plots->fcomb8M,object.Vcombine3,object.Vangle_combine);
//	ShowMessage(4,"end combine h_h angles",object.Vangle_combine[0]);

	//all visible 
	


	//if(*Jcomb1||*Jcomb2||*Jcomb3||*Jcomb4||*Jcomb5||*Jcomb6||*Jcomb7||*Jcomb8 ){
//		return(true);
	//}
	//else{
	//	return(false);
	//}
	return(true);
}

